package io.tij;

import static util.Print.*;

import java.io.Externalizable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

import util.Constants;


public class Blip3 implements Externalizable {
	private int i;
	private String s;

	public Blip3() {
		print("#Blip3 default Constructor");
	}

	public Blip3(int i, String a) {
		print("#Blip3(int i, String x)");
		this.i = i;
		this.s = a;
	}

	public String toString() {
		return i + s;
	}

	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		print("#readExternal");
		i = in.readInt();
		s = (String)in.readObject();
	}

	public void writeExternal(ObjectOutput out) throws IOException {
		print("#writeExternal");
		out.writeInt(i);
		out.writeObject(s);
	}

	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
		String filepath = Constants.IO_FILE_BASE_PATH + "Blip3.out";
		
		Blip3 blip3 = new Blip3(47, " A String");
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
				filepath));
		
		print("#Saving objects...");
		out.writeObject(blip3);
		out.close();
		
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(filepath));
		print("#Fetching objects...");
		blip3 = (Blip3)in.readObject();
		print(blip3);
		in.close();
	}
}
